package com.xlh.websocket;

import com.xlh.security.UserInfoHolder;
import com.xlh.util.SpringContextUtil;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author cheer
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {

    private UserInfoHolder userInfoHolder = SpringContextUtil.getBean(UserInfoHolder.class);

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        sec.getUserProperties().put("userId", userInfoHolder.getUserId());
        sec.getUserProperties().put("roleId", userInfoHolder.getUser().getRole());
    }
}
